package com.hanainfo.hanaApp;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Random;

import org.json.simple.JSONObject;
import org.json.simple.JSONValue;


public class test {
	private static int[] six = {0,0,0,0,0,0};
	
	public static void main(String args[]){
		String spec = "http://www.645lotto.net/ajax_jsonNew.asp?sGameNo=479";	
	    URL url = null;
	    URLConnection con = null;
	    JSONObject job = null;
		try{
			url= new URL(spec);
			con = url.openConnection();
			//con.setUseCaches(false);
			
			String api = "";
			String line = null;
			BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
			while ((line=br.readLine())!= null){
				api = api+line + "\n";
			}
			Object ob = JSONValue.parse(api);
			job = (JSONObject) ob;
			
			
			
		}catch (Exception e) {
			// TODO: handle exception
		}
		for(int i=0 ; i<6 ; i++){
			Random r = new Random();
			int x = Math.abs(r.nextInt(45)+1);
			setNumber(i,x);
		}
		setBubble();
		int count=0;
		HashMap<String, Object> G = new HashMap<String, Object>();
		int[] six2 = {2, 9, 17, 20 , 22, 38};
		
		for(int i=0 ; i<6 ; i++){
			int a = six[i];
			for(int j=0 ; j<6 ; j++){
				int b = six2[j];
				
				if(a==b){
					System.out.println("Match!! a = "+a+", b="+b);
					count++;
				}else{
					System.out.println("No match.. a = "+a+", b="+b);
				}
			}
		}
		System.out.println("Total Match : "+count);
		System.out.println("first ball : "+job.get("FirstBall"));
	}
	public static void setNumber(int i, int x){
		int flag = 1;
		for(int y=0 ; y<i ; y++){
			if(flag==0){
				y=0;
			}
			if(six[y]==x){
				Random r = new Random();
				x = Math.abs(r.nextInt(45)+1);
				flag = 0;
				y--;
			}else{
				flag = 1;
			}
		}
		six[i]=x;
	}
	
	public static void setBubble(){
		int temp;
		int flag=1;
		
		for(int y=1; y<6;y++){
			if(flag==0){
				y=1;
			}
			temp=six[y];
			if(six[y-1]>temp){
				six[y]=six[y-1];
				six[y-1]=temp;
				flag=0;
				y--;
			}else{
				flag=1;
			}
		}
	}
}
